package com.ruoyi.swla2.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swla2.domain.BasicDfq;
import com.ruoyi.swla2.service.IBasicDfqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 大分区配置Controller
 *
 * @author gdqt
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/region/basicDfq")
public class BasicDfqController extends BaseController {
    @Autowired
    private IBasicDfqService basicDfqService;

    /**
     * 查询大分区配置列表
     */
    @PreAuthorize("@ss.hasPermi('region:basicDfq:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicDfq basicDfq) {
        startPage();
        List<BasicDfq> list = basicDfqService.selectBasicDfqList(basicDfq);
        return getDataTable(list);
    }

    /**
     * 导出大分区配置列表
     */
    @PreAuthorize("@ss.hasPermi('region:basicDfq:export')")
    @Log(title = "大分区配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicDfq basicDfq) {
        List<BasicDfq> list = basicDfqService.selectBasicDfqList(basicDfq);
        ExcelUtil<BasicDfq> util = new ExcelUtil<BasicDfq>(BasicDfq.class);
        util.exportExcel(response, list, "大分区配置数据");
    }

    /**
     * 获取大分区配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('region:basicDfq:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(basicDfqService.selectBasicDfqByID(ID));
    }

    @PreAuthorize("@ss.hasPermi('region:basicDfq:query')")
    @GetMapping(value = "/getBasicDfqByAreaId")
    public AjaxResult getBasicDfqByAreaId(@RequestParam("areaId") String areaId) {
        return success(basicDfqService.getBasicDfqByAreaId(areaId));
    }

    /**
     * 新增大分区配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDfq:add')")
    @Log(title = "大分区配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicDfq basicDfq) {
        basicDfq.setTenantId(this.getTenantId());
        return toAjax(basicDfqService.insertBasicDfq(basicDfq));
    }

    /**
     * 修改大分区配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDfq:edit')")
    @Log(title = "大分区配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicDfq basicDfq) {
        return toAjax(basicDfqService.updateBasicDfq(basicDfq));
    }

    /**
     * 删除大分区配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDfq:remove')")
    @Log(title = "大分区配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs) {
        return toAjax(basicDfqService.deleteBasicDfqByIDs(IDs));
    }
}
